<?php
/**
 * Created by leiying
 * Date: 2017/11/15
 * Time: 15:22
 */
//分类
include_once(GZ_PATH . '/includes/common_func.php');
include_once(GZ_PATH . '/includes/category_func.php');
class categoryAction extends Action
{
    /**分类列表
     * @author leiying
     */
    public function category_list(){
        $category_id = _POST("category_id", 0);

        $sql = "SELECT `id` category_id,`name`,`cover_pic`,`tid`,`url` FROM km_goods_category WHERE `status`=1 AND `pid`=0 order by sort asc";
        $list = $this->getAll($sql);
        if($list){
            if($category_id == 0){$category_id = $list[0]['category_id'];}

            foreach($list as &$v){
                if($v['category_id'] == $category_id){
                    $sql = "SELECT `id` category_id,`name`,`pid` FROM km_goods_category WHERE `status`=1  order by sort asc";
                    $res = $this->getAll($sql);
                    $tree = list_to_tree($res,'category_id','pid','_child',$category_id);
                    $v['child']['category_info'] = $tree;
                    $v['child']['top_info']['cover_pic'] = GZ_Api::get_url($v['cover_pic']);
                    $v['child']['top_info']['tid'] = $v['tid'];
                    $v['child']['top_info']['url'] = $v['url'];
                    unset($v['cover_pic']);
                    unset($v['tid']);
                    unset($v['url']);
                }else{
                    unset($v['cover_pic']);
                    unset($v['tid']);
                    unset($v['url']);
                }
            }
        }
        GZ_Api::outPut($list);

    }

    /**分类商品列表接口
     * @author leiying
     */
    public function goods_list(){
        $page_size   = GZ_Api::$pagination['count'];    //分页设置
        $page        = GZ_Api::$pagination['page'];     //分页设置
        $category_id = _POST("category_id", 0);
        $sort_type = _POST("sort_type", "all");
        $sort_action = _POST("sort_action", "all");
        if($category_id == 0){
            GZ_Api::message('分类id非法', 2);
        }
        $res = get_goods($category_id,$sort_type,$sort_action,$page,$page_size);
        GZ_Api::outPut($res);

    }


}
